fix: derive activity counts from paged nodes instead of search [CM-1220]#4192
Merged
Conversation
Signed-off-by: Mouad BANI <mouad-mb@outlook.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR refactors the packages_worker GitHub repo enricher’s activity snapshot logic to compute PR/issue volume metrics directly from the paged PR/issue nodes already fetched for median calculations, removing reliance on GitHub GraphQL search(issueCount) aggregates. It also trims the summary GraphQL query and updates types/queries to support the new calculations (notably adding closedAt on PR nodes and fetching repository.issues(states: OPEN).totalCount for “open now”).
Changes:
- Remove GraphQL search-based aggregate counts from the summary query and derive 12-month / 6-month activity counts from paged PR/issue nodes.
- Add
closedAtto PR paging andPrNodetyping to enable “closed-unmerged” PR counting. - Add a direct
openIssuestotal count query on the repository and simplify date window helpers accordingly.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| services/apps/packages_worker/src/enricher/fetchActivitySnapshot.ts | Refactors metrics calculation away from search aggregates; trims summary query; adds closedAt to PR paging; uses repo openIssues totalCount. |
| services/apps/packages_worker/src/enricher/computeMedians.ts | Extends PrNode shape to include closedAt to match the updated GraphQL paging query. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+340
to
+342
| const issuesOpenedLast6m = issueResult.nodes.filter( | ||
| (n) => new Date(n.createdAt) >= since6m, | ||
| ).length |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request refactors how pull request (PR) and issue activity metrics are computed and retrieved in the
fetchActivitySnapshot.tsworker. The main change is moving from GraphQL search-based aggregate queries to calculating metrics directly from the fetched PR and issue nodes, making the code more reliable and easier to maintain. It also introduces some small improvements and simplifications to the type definitions and query parameters.Key changes include:
Metrics Calculation Refactor
Replaces GraphQL search queries for PR and issue counts with direct calculations on the fetched PR and issue nodes, improving accuracy and reducing complexity. For example, PRs opened, merged, and closed-unmerged in the last 12 months are now counted from the node data rather than relying on search queries. [1] [2] [3] [4] [5]
Calculates issues opened in the last 6 months by filtering the fetched issue nodes by
createdAt, instead of using a separate search query.GraphQL Query and Type Updates
Removes unused search query variables and fields from the GraphQL summary query, simplifying the query structure. [1] [2]
Adds
closedAtto the PR node interface and GraphQL query, enabling accurate computation of closed-unmerged PRs. [1] [2]Adds a direct query for the current number of open issues (
openIssues) on the repository. [1] [2]Code and Type Simplifications
Removes the
toDateStringhelper and unused date string fields from the date window builder, as they are no longer needed for search queries. [1] [2]Cleans up unused type definitions related to the old search-based approach.
These changes make the codebase more maintainable and ensure that activity metrics are calculated consistently from the same set of fetched data.
Note
Medium Risk
Published enrichment metrics may shift if search totals previously disagreed with the paged 12m window or if paging stops early on very active repos.
Overview
Activity snapshot metrics in
fetchActivitySnapshotno longer use GitHub GraphQL searchissueCountqueries. PR and issue volume fields (opened/merged/closed in the 12m window, 6m issue splits) are derived from the same paged PR/issue nodes already fetched for median calculations.The summary query is trimmed to commit history plus
repository.openIssuesfor issues open now. PR paging now requestsclosedAt(andPrNodeis updated) so closed-unmerged PRs can be counted asclosedAt && !mergedAt. Date-window helpers drop search-only date strings and exposesince6mfor filtering 6-month issue opens on the node list.Reviewed by Cursor Bugbot for commit 56a718a. Bugbot is set up for automated code reviews on this repo. Configure here.